
*merge convexity data
use "$jfqa_rep/16_Five_Day_Convex.dta", clear

merge 1:1 permno year month using "$jfqa_rep/17_Ten_Day_Convex.dta"
drop _merge

merge 1:1 permno year month using "$jfqa_rep/18_Monthly_Convex.dta"
drop _merge

gen monthyear=ym(year, month)
order permno year month monthyear
sort permno year month

*define dummies for first and last month of permno
gen first_dummy=0 
replace first_dummy=1 if permno~=permno[_n-1]

gen last_dummy=0
replace last_dummy=1 if permno~=permno[_n+1]

*replace convexity measures if first, last, or missing 
foreach i in five_day_convex_div five_day_convex_split ten_day_convex_div ten_day_convex_split convexity_div convexity_split {
replace `i'=. if miss_dummy==1 | last_dummy==1 | first_dummy==1
}

drop miss_dummy first_dummy last_dummy

save "$jfqa_rep/19_Append_Convex.dta", replace
